package com.llmcu.graphic.designpatterns.interpreter;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

@Setter
@Getter
public class PrimitiveCommandNode extends CommandNode {
    public static final String GO_TOKEN = "go";
    public static final String LEFT_TOKEN = "left";
    public static final String RIGHT_TOKEN = "right";
    private String value;

    @Override
    public void parse(Context context) {
        String currentToken = context.getCurrentToken();
        if (Objects.equals(currentToken, GO_TOKEN)) {
            value = GO_TOKEN;
        } else if (Objects.equals(currentToken, RIGHT_TOKEN)) {
            value = RIGHT_TOKEN;
        } else if (Objects.equals(currentToken, LEFT_TOKEN)) {
            value = LEFT_TOKEN;
        } else {
            throw new RuntimeException("primitiveCommand token error");
        }
        context.skip(value);
    }

    @Override
    public String toString() {
        return value;
    }
}
